﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StoragePeriod.Data;
using StoragePeriod.Web.Common;
using StoragePeriod.Common;

namespace StoragePeriod.Web.SysManage
{
    public partial class PanelsContent : SecurityPage
    {

        //public override string PrivCode()
        //{
        //    return "Delfault";
        //}

        private void LoadData()
        {
            PanelsConfig md = PanelsConfig.Where("TypeId=@0", Convert.ToInt32(EnumData.PanelsType.公告内容)).OrderBy(p => p.id).FirstOrDefault();
            if(md!=null)
                this.E_Content.Value = md.Contents;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            LoadData();
        }

        protected void btPost_Click(object sender, EventArgs e)
        {
            PanelsConfig md = PanelsConfig.Where("TypeId=@0", Convert.ToInt32(EnumData.PanelsType.公告内容)).OrderBy(p => p.id).FirstOrDefault();
            if (md != null)
            {
                md.Contents = this.E_Content.Value;
                PanelsConfig.Update(md, "id=@0", md.id);
            }
            else
            {
                PanelsConfig mdAdd = new PanelsConfig();
                mdAdd.Contents = this.E_Content.Value;
                mdAdd.TypeId = Convert.ToInt32(EnumData.PanelsType.公告内容);
                PanelsConfig.Insert(mdAdd);
            }
            Response.Redirect("PanelsContent.aspx");
        }
    }
}